#!/bin/bash

# Set up environment
HERE="$(dirname "$(readlink -f "${0}")")"

function show_usage {
	echo "First argument must be one of these: daemon gui cli"
}

function launch_daemon {
	exec "${HERE}"/opt/librevault/bin/librevault-daemon "$@"
}
function launch_gui {
	exec "${HERE}"/opt/librevault/bin/librevault-gui "$@"
}
function launch_cli {
	exec "${HERE}"/opt/librevault/bin/librevault-cli "$@"
}

# If no arguments, then launch GUI (and it will launch daemon by itself)
if [[ $# -eq 0 ]]; then
	launch_gui
fi

LAUNCH_APP=$1
shift

case "$LAUNCH_APP" in
	"daemon")
		launch_daemon $@
	;;
	"gui")
		launch_gui $@
	;;
	"cli")
		launch_cli $@
	;;
	*)
		show_usage
	;;
esac
